package com.four.bmm.service;


import com.four.bmm.dao.IUserDao;
import com.four.bmm.entity.User;
import com.four.bmm.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

public class UserService {
    SqlSession session=SqlSessionFactoryUtil.getSqlSession();
    IUserDao userDao=session.getMapper(IUserDao.class);

    public boolean regist(User user){
       boolean flag = false;
       try {
            flag= userDao.regist(user);
            session.commit();
        }catch (Exception e){
            session.close();
        }
       return flag;
    }
    public boolean checkUserByName(String username){
        User user= userDao.checkUserByName(username);
        if(user!=null){
            return  true;
        }else {
            return  false;
        }
    }
    public User login(User user){
        return userDao.login(user);
    }

    public boolean uploadHeader(User user){
        boolean flag = false;
        flag= userDao.uploadHeader(user);
        session.commit();
        return flag;
    }
}
